package 测试;

import java.util.*;

public class person {
	Scanner s = new Scanner(System.in);

	public Struct Sellticket() {

		System.out.println("请问需要购买几张票");
		int Votes = s.nextInt();
		// 创建头节点
		Struct Head = new Struct();
		Struct temp = Head;
		for (int i = 0; i < Votes; i++) {
			Struct p = new Struct();
			System.out.println("请输入您的姓名:");
			p.Name = s.next();
			System.out.println("请输入您要购买电影的名字:");
			p.Movie = s.next();
			System.out.println("请输入您要购买的电影场次:");
			p.Scene = s.next();
			System.out.println("输入您的座位:");
			p.Seat = s.next();

			temp.next = p;
			temp = p;
		}
		temp.next = null;
		System.out.println("购票成功");
		return Head;
	}

	public Struct Refundticket(Struct Head) {
		Struct temp = Head.next;
		Struct p = Head;// 当前节点的前节点
		System.out.println("输入您的姓名:");
		String name = s.next();
		while (temp != null) {
			if (temp.Name.contentEquals(name)) {
				p.next = temp.next;
				System.out.println("退票成功");
			}
			temp = temp.next;
			p = p.next;

		}

		return Head;
	}

	public void Traversinglist(Struct Head) {
		Struct temp = Head.next;
		while (temp != null) {
			System.out.println(temp.Name + " " + temp.Movie + " " + temp.Scene + " " + temp.Seat);
			temp = temp.next;
		}

	}

	public static void main(String[] args) {
		person p = new person();
		Struct Head;
		Head = p.Sellticket();
		p.Traversinglist(Head);
		Head = p.Refundticket(Head);
		p.Traversinglist(Head);
	}

}